
package org.masterinftel.scrumpmt.adapters;

import java.util.List;

import org.masterinftel.scrumpmt.R;
import org.masterinftel.scrumpmt.json.model.ProductoJSON;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ProductsListAdapter extends ArrayAdapter<ProductoJSON> {

    private final Activity context;
    private final List<ProductoJSON> productsList;

    public ProductsListAdapter(Activity context, List<ProductoJSON> productsList) {
        super(context, R.layout.productslistelement, productsList);
        this.context = context;
        this.productsList = productsList;
    }

    static class ViewHolder {
        protected TextView name;
        protected TextView customer;

    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View item = null;
        if (convertView == null) {
            LayoutInflater inflater = context.getLayoutInflater();
            item = inflater.inflate(R.layout.productslistelement, null);
            final ViewHolder viewHolder = new ViewHolder();
            viewHolder.name = (TextView) item.findViewById(R.id.product_name);
            viewHolder.customer = (TextView) item.findViewById(R.id.product_customer);
            item.setTag(viewHolder);
        } else {
            item = convertView;

        }
        ViewHolder holder = (ViewHolder) item.getTag();

        holder.name.setText(productsList.get(position).getNombre());
        holder.customer.setText(productsList.get(position).getNomcli());

        return (item);
    }

}
